#include "UdpServer.hpp"
#include "User.hpp"

#include <memory>
using namespace LogModule;

int main(int argc, char *argv[])
{
    ENABLE_CONSOLE_LOG();
    if (argc != 2)
    {
        std::cerr << "Usage: " << argv[0] << " localport" << std::endl;
        Die(USAGE_ERR);
    }
    // std::string ip = argv[1];
    uint16_t port = std::stoi(argv[1]);

    std::shared_ptr<UserManager> user_manager = std::make_shared<UserManager>();

    std::unique_ptr<UdpServer> server = std::make_unique<UdpServer>(
        port);

    server->RegisterSerive([&user_manager](const InetAddr &user)
                           { user_manager->AddUser(user); },
                           [&user_manager](int sockfd, const std::string &message)
                           { user_manager->Router(sockfd,message); },
                           [&user_manager](const InetAddr &user)
                           {user_manager->DelUser(user);}
                            );
                            
    server->InitServer();
    server->Start();

    return 0;
}